<script>
    // 深拷贝
    function isObject(val) {
        return Object(val) === val
    }
    function deepCopy(source, hash = new WeakMap()) {
        if (!isObject(source)) return source
        if (hash.has(source)) return hash.get(source)
        let target = Array.isArray(source) ? [] : {}
        hash.set(source, target)
        for (let k of Reflect.ownKeys(source)) {
            if (isObject(source[k])) {
                target[k] = deepCopy(source[k], hash)
            } else {
                target[k] = source[k]
            }
        }
        return target
    }

    let a = {
        a: function () { console.log('a') },
        regexp: new RegExp('regexp')
    }

    let b = deepCopy(a)
    console.log(a, b)

</script>